package com.demo.database.mapper;


import com.demo.database.data.TDemoEmployee;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 数据库访问映射接口
 * @cuthor luoxiaojiang
 * @createTime 2019年11月07日15:01:20
 * @Verson 1.0.0
 */

public interface TDemoEmployeeMapper {

    @Results(id = "employeeResultMap", value = {
            @Result(property = "employeeId", column = "employee_id", id = true),
            @Result(property = "employeeName", column = "employee_name"),
            @Result(property = "idNumber", column = "idnumber"),
            @Result(property = "employeeGender", column = "employee_gender"),
            @Result(property = "position", column = "position_id",
                    one = @One(select = "com.demo.database.mapper.TDemoPositionMapper.positionQueryID")),
            @Result(property = "education", column = "education"),
            @Result(property = "mailbox", column = "mailbox"),
            @Result(property = "tel", column = "tel"),
            @Result(property = "address", column = "address"),
            @Result(property = "department", column = "department_id",
                    one = @One(select = "com.demo.database.mapper.TDemoDepartmentMapper.departmentQueryID")),
            @Result(property = "entryTime", column = "entry_time"),
            @Result(property = "salary", column = "salary"),
            @Result(property = "bankcardNumber", column = "bankcard_number"),
            @Result(property = "operTime", column = "opertime")
    })

    @SelectProvider(type =EmployeeProvider.class , method = "getQueryAllSql")
    public List<TDemoEmployee> employeeQueryAllSql(String context) throws Exception;

    @Select("select * from t_demo_employee where employee_id=#{id}")
    @ResultMap("employeeResultMap")
    public TDemoEmployee employeeQueryID(Integer id) throws Exception;

    @Insert("insert into t_demo_employee (employee_name,idnumber,employee_gender,position_id,education,mailbox,tel,address,department_id,entry_time,salary,bankcard_number,opertime)"
            + "values (#{employeeName},#{idNumber},#{employeeGender},#{position.positionId},#{education},#{mailbox},#{tel},#{address},#{department.departmentId},#{entryTime},#{salary},#{bankcardNumber},#{operTime})")
    public void employeeAdd(TDemoEmployee employee) throws Exception;

    @Update("update t_demo_employee set employee_name=#{employeeName},idnumber=#{idNumber},employee_gender=#{employeeGender},position_id=#{position.positionId}," +
            "education=#{education},mailbox=#{mailbox},tel=#{tel},address=#{address},department_id=#{department.departmentId},entry_time=#{entryTime},salary=#{salary},bankcard_number=#{bankcardNumber},opertime=#{operTime} where employee_id=#{employeeId}")
    public void employeeUpd(TDemoEmployee employee) throws Exception;

    @DeleteProvider(type = EmployeeProvider.class, method = "getQueryDelSql")
    public void employeeDel(@Param("employeeIds") String... employeeIds) throws Exception;
}
